//
//  HomeTranforOrderGoodsInfoTableViewCell.m
//  ZJControlsClass
//
//  Created by mac on 2024/12/5.
//

#import "HomeTranforOrderGoodsInfoTableViewCell.h"


@interface HomeTranforOrderGoodsInfoTableViewCell ()

@property (nonatomic,strong) UILabel * nameLabel;
@property (nonatomic,strong) UILabel * sizeLabel;
@property (nonatomic,strong) UILabel * numLabel;
@property (nonatomic,strong) UIButton * selectBtn;



@end





@implementation HomeTranforOrderGoodsInfoTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self){
     
        [self configUI];
        
        
    }
    
    return self;
}



-(void)configUI{
    
    
    [self.contentView addSubview:self.nameLabel];
    [self.contentView addSubview:self.sizeLabel];
    [self.contentView addSubview:self.numLabel];
    [self.numLabel addSubview:self.selectBtn];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).with.offset(ALIGN_WIDTH_PT(12));
        make.top.equalTo(self.contentView);
        make.size.equalTo(@(CGSizeMake((SCREEN_WIDTH - ALIGN_WIDTH_PT(24)) / 3, ALIGN_HEIGHT_PT(32))));
    }];

    [self.sizeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_right);
        make.centerY.equalTo(self.nameLabel.mas_centerY);
        make.size.equalTo(@(CGSizeMake((SCREEN_WIDTH - ALIGN_WIDTH_PT(24)) / 3, ALIGN_HEIGHT_PT(32))));
    }];
    
    [self.numLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.sizeLabel.mas_right);
        make.centerY.equalTo(self.nameLabel.mas_centerY);
        make.size.equalTo(@(CGSizeMake((SCREEN_WIDTH - ALIGN_WIDTH_PT(24)) / 3, ALIGN_HEIGHT_PT(32))));
    }];
    
    [self.selectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.nameLabel.mas_centerY);
        make.right.equalTo(self.numLabel.mas_right).with.offset(-ALIGN_WIDTH_PT(14.5));
        make.size.equalTo(@(CGSizeMake(ALIGN_WIDTH_PT(16), ALIGN_WIDTH_PT(16))));
    }];
    
}



-(void)setModel:(HomeTransforOrderInfoAreaListModel *)model{
    _model = model;
    
    self.nameLabel.text = self.model.goodsName;
    self.sizeLabel.text = self.model.goodsSpec;
    self.numLabel.text = self.model.goodsNum;
    
    if (model.IsSelect){
        [self.selectBtn setImage:[UIImage imageNamed:@"选择"] forState:(UIControlStateNormal)];
    }else{
        [self.selectBtn setImage:[UIImage imageNamed:@"未选"] forState:(UIControlStateNormal)];
    }
}

-(void)respondsTo_selectBtn:(UIButton *)sender{

    if (self.model.IsSelect){
        self.model.IsSelect = NO;
        [self.selectBtn setImage:[UIImage imageNamed:@"未选"] forState:(UIControlStateNormal)];
    }else{
        self.model.IsSelect = YES;
        [self.selectBtn setImage:[UIImage imageNamed:@"选择"] forState:(UIControlStateNormal)];
    }
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(chooseTransforOrderTool:)]){
        [self.delegate chooseTransforOrderTool:self.model];
    }
    
    
}




#pragma mark -- 懒加载
-(UILabel *)nameLabel{
    if (!_nameLabel){
        _nameLabel = [UILabel new];
        _nameLabel.textColor = [UIColor blackColor];
        _nameLabel.font = FONT12;
        _nameLabel.textAlignment = NSTextAlignmentCenter;
        _nameLabel.text = @"货物名称";
    }
    return _nameLabel;
}


-(UILabel *)sizeLabel{
    if (!_sizeLabel){
        _sizeLabel = [UILabel new];
        _sizeLabel.textColor = [UIColor blackColor];
        _sizeLabel.font = FONT12;
        _sizeLabel.textAlignment = NSTextAlignmentCenter;
        _sizeLabel.text = @"货物名称";
    }
    return _sizeLabel;
}

-(UILabel *)numLabel{
    if (!_numLabel){
        _numLabel = [UILabel new];
        _numLabel.textColor = [UIColor blackColor];
        _numLabel.font = FONT12;
        _numLabel.textAlignment = NSTextAlignmentCenter;
        _numLabel.text = @"货物名称";
        _numLabel.userInteractionEnabled = YES;
    }
    return _numLabel;
}


-(UIButton *)selectBtn{
    if (!_selectBtn){
        _selectBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        [_selectBtn setImage:[UIImage imageNamed:@"未选"] forState:(UIControlStateNormal)];
        [_selectBtn setImage:[UIImage imageNamed:@"选择"] forState:(UIControlStateSelected)];
        [_selectBtn addTarget:self action:@selector(respondsTo_selectBtn:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return _selectBtn;
}



@end
